package com.aaa.service.fpa.impl;

import com.aaa.aspect.InsertAnn;
import com.aaa.controller.BaseController;
import com.aaa.dao.fpa.TesterFpaDao;
import com.aaa.dao.fpa.ViewTestResultFpaDao;
import com.aaa.entity.Result;
import com.aaa.entity.fpa.TestResultFpa;
import com.aaa.entity.fpa.TesterFpa;
import com.aaa.service.fpa.TesterFpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/**
 * @author ：陈昂（731712841@qq.com）
 * @date ：Created in 2022/9/7 23:04
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class TesterFpaServicImpl extends BaseController implements TesterFpaService {
    @Autowired
    TesterFpaDao testerFpaDao;
    @Autowired
    ViewTestResultFpaDao viewTestResultFpaDao;
    @Override
    public TesterFpa queryByPhone(String phone) {
        return testerFpaDao.queryPhone(phone);
    }

    /**
     * 添加测试者信息
     *
     * @param testerFpa
     * @return
     */
    @InsertAnn
    @Override
    public int addQuery(TesterFpa testerFpa) {
        return testerFpaDao.addQuery(testerFpa);
    }

    @Override
    public int insertBatch(List<TestResultFpa> entities) {
        int i = testerFpaDao.insertBatch(entities);
        return i;
    }
    @Override
    public Result seleResult(Integer testerId) {
        List<Map> viewFpa = viewTestResultFpaDao.seleResultFpa(testerId);
       Integer red = Integer.valueOf(viewFpa.get(0).get("red_count").toString()) ;
        Integer yellow = Integer.valueOf(viewFpa.get(0).get("yellow_count").toString());
        Integer blue = Integer.valueOf(viewFpa.get(0).get("blue_count").toString()) ;
        Integer green =Integer.valueOf(viewFpa.get(0).get("green_count").toString()) ;
        System.err.println(red > yellow && red > blue && red > green);
        System.err.println(yellow > red && yellow > blue && yellow > green);
        System.err.println(blue > red && blue > yellow && blue > green);
        System.err.println(green > red && green > yellow && green > blue);
        if (red > yellow && red > blue && red > green) {
           return  success("/views/fpa/red.jsp");
        } else if (yellow > red && yellow > blue && yellow > green) {
           return  success("/views/fpa/yellow.jsp");
        } else if (blue > red && blue > yellow && blue > green) {
           return  success("/views/fpa/blue.jsp");
        } else if (green > red && green > yellow && green > blue) {
           return  success("/views/fpa/green.jsp");
        } else {
            return  success( "/views/fpa/All.jsp");
        }
    }
}
